//
// Created by Administrator on 2021/11/10.
// Shader程序对象，方便创建-链接-编译shader
//

#ifndef LEARNREALTIMERENDERING_SHADERPROGRAM_H
#define LEARNREALTIMERENDERING_SHADERPROGRAM_H

#include "Common.h"

class ShaderProgram
{
public:
    ShaderProgram() = default;
    ShaderProgram(const std::string& vsPath,
                  const std::string& fsPath,
                  const std::string& tcsPath = "",
                  const std::string& tesPath = "",
                  const std::string& gsPath = "");

    void Use() const { glUseProgram(m_ID); }
    void Delete() const { glDeleteProgram(m_ID); }

    void SetUniformBool(const std::string& name, GLboolean b) const
    {
        glUniform1i(glGetUniformLocation(m_ID, name.c_str()), b);
    }
    void SetUniformMatrix(const std::string& name, const GLfloat* value, bool transpose) const
    {
        glUniformMatrix4fv(glGetUniformLocation(m_ID, name.c_str()), 1, transpose, value);
    }

    const GLuint& ID() const { return m_ID; }

private:
    enum CompileType {Shader = 0, Program = 1};

    static bool CheckCompile(GLuint shader, CompileType type);
    void LoadAndCompileShader(GLenum type, const std::string& path) const;

    GLuint m_ID;
};

#endif //LEARNREALTIMERENDERING_SHADERPROGRAM_H
